package com.tuyue.police.controller.vip;

import com.tuyue.police.biz.IUserBiz;
import com.tuyue.police.enums.ResultEnum;
import com.tuyue.police.exception.MyException;
import com.tuyue.police.pojo.User;
import com.tuyue.police.util.Result;
import com.tuyue.police.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 王金海
 * @Description:
 * @Date: Created by Administrator on 2018/3/13.
 * @Modified By:
 */
@RestController
@RequestMapping("vip/user")
public class LoginController {

    @Autowired
    private IUserBiz userBiz;

    /**
     * 登陆
     * @param userName
     * @param userPassword
     * @return
     */
    @PostMapping("login")
    public Result login(@RequestParam String userName,@RequestParam String userPassword){
        User user = userBiz.login(userName, userPassword);
        return ResultUtil.success(user);
    }

    @PostMapping("regust")
    public Result regist(@RequestBody User user){
        if (ObjectUtils.isEmpty(user)) {
            throw new MyException(ResultEnum.USER_NOTNULL);
        }
        User newuser =userBiz.regist(user);
        return ResultUtil.success(newuser);
    }
    @GetMapping("findById/{userId}")
    public Result findById(@PathVariable Long userId){
        User newuser =userBiz.findById(userId);
        return ResultUtil.success(newuser);
    }
}
